﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KBManagement.DAL;
using KBManagement.Library;
namespace KBManagement.OrderProcess
{
    sealed class ProductsState
    {


        private static readonly ProductsState _instance = new ProductsState();
        List<ProductItem> items;
        public int NumberOfItem()
        {
            return items.Count;
        }
        public void ChangeProduct(string fromProduct, string toProduct)
        {
            var fromItem = items.Find(x => x.product.Name == fromProduct);
            var toItem = items.Find(x => x.product.Name == toProduct);
            toItem.ChangeProduct(fromItem);
        }
        public ProductItem GetItem(Product product)
        {
            return items.Find(x => x.product.Name == product.Name);
        }
        public List<ProductItem> GetItemsByCategoryAndStatus(Product p, bool status)
        {
            return items.FindAll(x => x.product.CategoryID == p.CategoryID && x.Status == status);
        }
        public void AddProduct(Product product)
        {
            ProductItem p = new ProductItem(product);
            items.Add(p);
        }

        private ProductsState()
        {
            items = new List<ProductItem>();

        }
        public static ProductsState GetProductsState()
        {
            return _instance;
        }
    }
}
